﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BonusSet.aspx.cs" Inherits="YY.Web.MyAgent.BonusSet" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>代理商资金分红设置表</title>
    <link href="/jQuery/PlugIns/artdialog/ui-dialog.css" rel="stylesheet" type="text/css" />
    <link href="/skin/default/style.css" rel="stylesheet" type="text/css" />
    <link href="../css/editlinkmodule.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" charset="utf-8" src="/jQuery/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/jQuery/PlugIns/Validform/Validform_v5.3.2_min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/jQuery/PlugIns/editor/kindeditor-min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/js/laymain.js"></script>
    <script type="text/javascript" charset="utf-8" src="/js/common.js"></script>
    <script type="text/javascript" charset="utf-8" src="../js/iframetabhelp.js"></script>
    <script type="text/javascript">
        $(function () {
            //初始化表单验证
            $("#form1").initValidform();
        });

        var agentHelper = {
            Init: function () { },
            _event: {
                showAddAgent: function () {
                    $("#hf_type").val("add");
                    $("#div_popupBg").show();
                    $("#div_showaddLink").show();
                },
                hideAddAgent: function () {
                    $("#div_popupBg").hide();
                    $("#div_showaddLink").hide();
                },
                addAgent: function () {
                    var minMoney = $("#txtMinMoney").val();
                    var maxMoney = $("#txtMaxMoney").val();
                    var share = $("#txtShare").val();

                    if (minMoney == "" || maxMoney == "") {
                        $("#span_money").html("金额不可为空");
                        $("#span_money").css("color", "red");
                        $("#txtMinMoney").focus();
                        return;
                    } else {
                        $("#span_money").html("*销量业绩不能为空(单位:元)");
                        $("#span_money").css("color", "gray");
                    }
                    if (share == "") {
                        $("#span_share").html("分红点不可为空");
                        $("#span_share").css("color", "red");
                        $("#txtShare").focus();
                        return;
                    }

                    var type = $("#hf_type").val();
                    if (type == "add") {
                        var tables = $("#div_links").find("table");
                        var html = "";
                        if (tables.length % 2 == 0) {
                            html += "<div class='link spcl'>";
                        } else {
                            html += "<div class='link'>";
                        }
                        html += " <table cellpadding='0' cellspacing='0'>";
                        html += "<tbody>";
                        html += "                 <tr>";
                        html += "                     <td class='td-link-text pl-10'>";
                        html += "                        " + minMoney+"-"+maxMoney + "";
                        html += "                     </td>";
                        html += "                     <td class='td-sep'></td>";
                        html += "                     <td class='td-link-href pl-10'>";
                        html += "                         <input class='link-mode' value='103' type='hidden'>";
                        html += "                         " + share + "";
                        html += "                     </td>";
                        html += "                     <td class='td-sep'></td>";
                        html += "                     <td class='td-operate pl-10'>";
                        html += "                         <div class='modify-panel'><a class='edit-btn' onclick='agentHelper._event.edit(this)'>编辑</a> <a class='del-btn' onclick='agentHelper._event.del(this)'>删除</a></div>";
                        html += "                     </td>";
                        html += "                     <td>&nbsp;</td>";
                        html += "                 </tr>";
                        html += "             </tbody>";
                        html += "         </table>";
                        html += "     </div>";
                        $("#div_links").append(html);
                    } else {//编辑
                        var divContainer = $("#div_links > div.link").eq($("#hdnEditIndex").val());
                        var money = minMoney + "," + maxMoney;
                        divContainer.find('td').eq(0).text(money);
                        divContainer.find('td').eq(2).text(share);
                    }
                    agentHelper._event.hideAddAgent();
                },
                edit: function (obj) {
                    $("#hf_type").val("edit");//区分编辑添加
                    var tr = $(obj).parents("tr");
                    var tdArr = $(tr).find("td");
                    var money = $.trim(tdArr.eq(0).text()); //
                    var share = $.trim(tdArr.eq(2).text()); //
                    var minMoney = money.split('-')[0];
                    var maxMoney = money.split('-')[1];
                    $("#txtMinMoney").val(minMoney);
                    $("#txtMaxMoney").val(maxMoney);
                    $("#txtShare").val(share);
                    $("#hdnEditIndex").val($("#div_links > div.link").index(tr.parents('div.link'))); //index
                    $("#div_popupBg").show();
                    $("#div_showaddLink").show();
                },
                del: function (obj) {
                    var div = $(obj).parents("div.link");
                    div.remove();
                },
                save:function() {
                    var jsondataStr = $("#hf_settingtemplate").val();
                    /*转换成对象*/
                    var jsondata = jQuery.parseJSON(jsondataStr);
                    var all = "";
                    //添加配置部分
                    //获取div下所有table 
                    var tables = $("#div_links").find("table");
                    var links = "[";//保存所有table
                    for (var i = 0; i < tables.length; i++) {
                        var trLength = $(tables[i]).find("tr");
                        for (var j = 0; j < trLength.length; j++) {
                            var tdArr = trLength.eq(j).find("td");
                            var money = $.trim(tdArr.eq(0).text());//
                            var share = $.trim(tdArr.eq(2).text());//
                            var link = '{"money":"' + money + '","share":"' + share + '"}';
                            if (i + 1 == tables.length) {
                                all = link;
                            } else {
                                all = link + ",";
                            }
                            links += all;
                        }
                    }
                    links += "]";
                    jsondata.allmoneysettings = links;
                    var userid = $("#hf_userid").val();
                    $.ajax({
                        type: "Post",
                        url: "BonusSet.aspx/Save",
                        //方法传参的写法一定要对，str为形参的名字,str2为第二个形参的名字     
                        data: "{'jsondata':'" + $.JSONStringify(jsondata) + "','userid':'" + userid + "'}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            //返回的数据用data.d获取内容
                            //resultCallBack(data.d);
                            alert(data.d);
                        },
                        error: function (err) {
                            alert(err.statusText);
                        }
                    });
                    //禁用按钮的提交     
                    return false;
                }
            }
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
         <asp:HiddenField runat="server" ID="hf_type" /><!--区分添加/编辑-->
        <asp:HiddenField runat="server" ID="hdnEditIndex"/><!--当前编辑的下标-->
        <asp:HiddenField runat="server" ID="hf_settingtemplate"/>
        <asp:HiddenField runat="server" ID="hf_userid"/>
        <!--导航栏-->
        <div class="location">
            <a href="javascript:history.back(-1);" class="back"><i></i><span>返回上一页</span></a>
            <a href="../Center.aspx" class="home"><i></i><span>首页</span></a>
            <i class="arrow"></i>
            <span>资金分红设置</span>
        </div>
        <div class="line10"></div>
        <!--/导航栏-->

        <!--内容-->
        <div id="floatHead" class="content-tab-wrap">
            <div class="content-tab">
                <div class="content-tab-ul-wrap">
                    <ul>
                        <li><a class="selected" href="javascript:;">基本信息</a></li>
                        <%--    <li><a href="javascript:;">证书上传</a></li>--%>
                    </ul>
                </div>
            </div>
        </div>

        <%--  <div class="tab-content">
            <dl>
                <dt>销量业绩</dt>
                <dd>
                    <asp:TextBox ID="txtMinMoney" Width="100" runat="server" CssClass="input normal" datatype="*1-8" OnKeyPress="if(((event.keyCode>=48)&&(event.keyCode <=57))||(event.keyCode==46)) {event.returnValue=true;} else{event.returnValue=false;}" nullmsg="请输入金额" sucmsg="可以使用"></asp:TextBox>
                    -
                    <asp:TextBox ID="txtMaxMoney" Width="100" runat="server" CssClass="input normal" datatype="*1-8" OnKeyPress="if(((event.keyCode>=48)&&(event.keyCode <=57))||(event.keyCode==46)) {event.returnValue=true;} else{event.returnValue=false;}" nullmsg="请输入金额"  sucmsg="可以使用"></asp:TextBox>
                    <span class="Validform_checktip">*销量业绩不能为空(单位:万元)</span>
                </dd>
            </dl>
            <dl>
                <dt>分红点数</dt>
                <dd>
                    </dd>
            </dl>
        </div>
        --%>
        <div class="ui-tabs-con" id="basicSetting">
            <div class="set-line mtb-5">
                <div class="set-title">分红列表：</div>
                <div class="set-ctrl-r"><a class="faiButton" href="javascript:;" onclick="agentHelper._event.showAddAgent()">添加配置</a> </div>
            </div>
            <div class="link-header">
                <table cellpadding="0" cellspacing="0">
                    <tbody>
                        <tr>
                            <td class="td-link-text pl-10">金额区间(元)</td>
                            <td class="td-sep">
                                <div class="sep"></div>
                            </td>
                            <td class="td-link-href pl-10">分红点(%)</td>
                            <td class="td-sep">
                                <div class="sep"></div>
                            </td>
                            <td class="td-operate pl-10">操作</td>
                            <td>&nbsp;</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="link-body link-body4pic" id="div_links">
                <asp:Repeater runat="server" ID="rpt_links">
                    <ItemTemplate>
                        <div <%#(Container.ItemIndex%2==0 )?"class='link spcl'":"class='link'"%>>
                            <table cellpadding="0" cellspacing="0">
                                <tbody>
                                    <tr>
                                        <td class="td-link-text pl-10">
                                            <%#(Eval("linktext")+"").Trim() %>
                                        </td>

                                        <td class="td-sep"></td>
                                        <td class="td-link-href pl-10">
                                            <input class="link-mode" value="103" type="hidden">
                                            <%#(Eval("href")+"").Trim() %>
                                        </td>
                                        <td class="td-sep"></td>
                                        <td class="td-operate pl-10">
                                            <div class="modify-panel"><a class="edit-btn" onclick="agentHelper._event.edit(this);">编辑</a> <a class="del-btn" onclick="agentHelper._event.del(this);">删除</a></div>
                                        </td>
                                        <td>&nbsp;</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>
            </div>
        </div>
        <div class="popupBg" id="div_popupBg" style="display: none;"></div>
        <div class="formDialog" style="left: 135px; top: 45px; display: none; z-index: 10000;" id="div_showaddLink">
            <div class="formTL">
                <div class="formTR">
                    <div class="formTC">添加分红配置</div>
                </div>
            </div>
            <div class="formBL">
                <div class="formBC">
                    <div class="formMSG" style="position: relative; width: 600px; height: 140px;">
                        <div class="set-line mtb-5">
                            <div class="set-title">销量业绩：</div>
                            <div class="set-ctrl">
                                <asp:TextBox ID="txtMinMoney" Width="100" runat="server" CssClass="input normal" OnKeyPress="if(((event.keyCode>=48)&&(event.keyCode <=57))||(event.keyCode==46)) {event.returnValue=true;} else{event.returnValue=false;}" nullmsg="请输入金额" sucmsg="可以使用"></asp:TextBox>
                                -
                                <asp:TextBox ID="txtMaxMoney" Width="100" runat="server" CssClass="input normal" OnKeyPress="if(((event.keyCode>=48)&&(event.keyCode <=57))||(event.keyCode==46)) {event.returnValue=true;} else{event.returnValue=false;}" nullmsg="请输入金额" sucmsg="可以使用"></asp:TextBox>
                                <span class="Validform_checktip" id="span_money">*销量业绩不能为空(单位:元)</span>
                            </div>
                        </div>
                        <div class="set-line mtb-5"></div>
                        <div class="set-line mtb-5" id="link-type-address">
                            <div class="set-title">分红点数：</div>
                            <div class="set-ctrl">
                                <asp:TextBox ID="txtShare" Width="100" runat="server" CssClass="input normal" MaxLength="2" OnKeyPress="if(((event.keyCode>=48)&&(event.keyCode <=57))||(event.keyCode==46)) {event.returnValue=true;} else{event.returnValue=false;}" nullmsg="请输入点数" errormsg="请输入1-2位数字" sucmsg="可以使用"></asp:TextBox>
                                <span class="Validform_checktip" id="span_share">*分红点数(百分比)</span>

                            </div>
                        </div>
                    </div>
                    <div class="formBtns">
                        <a href="javascript:;" class="abutton saveButton" onclick="agentHelper._event.addAgent();">确定</a>
                    </div>
                </div>
                <div style="height: 190px; width: 300px; display: none;" class="waitingP"></div>
                <!--框架加载图标-->
            </div>
            <a href="javascript:;" class="formX" onclick="agentHelper._event.hideAddAgent();"></a>
        </div>
        <!--/内容-->

        <!--工具栏-->
        <div class="page-footer">
            <div class="btn-wrap">
               <%-- <a href="javascript:;" class="btn" onclick="">确定</a>--%>
                <asp:Button ID="btnSubmit" runat="server" Text="提交" CssClass="btn" OnClientClick="agentHelper._event.save();" />
                <%--  <asp:Button ID="btnSubmitAudit" runat="server" Text="提交审核" CssClass="btn green" OnClick="btnSubmitAudit_Click" />--%>
                <input name="btnReturn" type="button" value="返回上一页" class="btn yellow" onclick="javascript: history.back(-1);" />
            </div>
        </div>
        <!--/工具栏-->
    </form>
</body>
</html>
